<template>
  <div>品牌管理
      <!-- 添加 -->
    <el-card class="box-card" style="margin:10px">
      <div>
        <span class="el-icon-goods"></span>
        <span> 品牌管理列表</span>
        <el-button
          style="float: right;"
          type="button"
          size="small"
          @click="goAddPage"
          >添加</el-button
        >
      </div>
    </el-card>

 <el-table :data="brandList" border style="width: 100%;margin:10px">
      <el-table-column prop="id" label="编号"> </el-table-column>
      <el-table-column prop="name" label="品牌名称"></el-table-column>
      <el-table-column prop="first_letter" label="品牌首字母"> </el-table-column>
      <el-table-column prop="sort" label="排序"> </el-table-column>
      <el-table-column prop="factory_status" label="品牌制造商"> 
<template slot-scope="scope">
          <el-switch
            v-model="scope.row.show_status"
            :active-value="1"
            :inactive-value="0"
          >
          </el-switch>
        </template>

      </el-table-column>
      <el-table-column prop="show_status" label="是否显示">
           <template slot-scope="scope">
          <el-switch
            v-model="scope.row.show_status"
            :active-value="1"
            :inactive-value="0"
          >
          </el-switch>
        </template>
           </el-table-column>
      <el-table-column  label="相关"> 
           <template slot-scope="scope">
          <p>商品:100{{ scope.row.stock}}</p>
          <p>评价:100{{ scope.row.product_sn}}</p>
        </template>
      </el-table-column>
       <el-table-column label="操作" width="200">
        <template>
          <el-button size="mini">编辑</el-button>
          <el-button type="primary" size="mini" class="btn">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 1.分页 
    current-page 当前页码
    page-sizes   每页有多少条数据的下拉列表
    page-size    当前的列表每页有多少条数据
    total        数据的总数量
    size-change   修改每页有多少条数据
    current-change 修改当前是第几页

    4.分页：修改了current-page、page-sizes page-size total属性绑定的值
    -->
   <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="listQuery.pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="listQuery.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      style="float: right"
    >
    </el-pagination>

  </div>
</template>

<script>
//引入
import { fetchBrandList } from "@/api/product";
export default {
  name: "brand",
  data: function () {
    return {
      brandList: [],
      //2.分页：定义变量
      listQuery: {
        pageSize: 5, //一页5条数据
        pageNum: 1, //当前页
      },
      total: 0, //总数量
    };
  },
   methods: {
    async getBrandList() {
      const res = await fetchBrandList(this.listQuery);
      console.log(res);
      this.brandList = res.data;
       //3.分页：获取数据的总量
      this.total = res.total;
    },
    handleSizeChange(val) {
        console.log("修改每页显示的条数 触发了",val);
      this.listQuery.pageSize = val;
      this.listQuery.pageNum = 1;
      //重新获取数据
      this.getBrandList();
      },
      //6.分页：修改当前页的页码
      handleCurrentChange(val) {
        console.log("修改当前页的页码 触发了", val);
         this.listQuery.pageNum = val;
      this.getBrandList();
      }
  },
   mounted() {
    this.getBrandList();
  },
};
</script>

<style>
.btn {
    color: #fff;
    background-color: hsl(2, 100%, 63%);
    border-color: hsl(2, 100%, 63%);
  }
</style>